package com.fqgj.sentry.controller.pc;

import com.fqgj.sentry.biz.pc.PolicyBusiness;
import com.fqgj.sentry.biz.pc.vo.policy.ExecutorPolicyVo;
import com.fqgj.sentry.biz.pc.vo.policy.PolicyInfo;
import com.fqgj.sentry.common.response.ApiOutput;
import com.fqgj.sentry.controller.pc.request.policy.AddPolicyVo;
import com.fqgj.sentry.controller.pc.request.policy.PolicySortVo;
import com.fqgj.sentry.controller.pc.request.policy.UpdatePolicyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 2017/7/19
 * Time: 下午5:15
 */
@RequestMapping("/policy")
@RestController
public class PolicyController {
    @Autowired
    private PolicyBusiness policyBusiness;

    /**
     * 策略 查找
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/{policyId}/info", method = RequestMethod.POST)
    public ApiOutput findById(@PathVariable(value = "policyId") Long policyId) {
        PolicyInfo policyInfo = policyBusiness.findById(policyId);
        return new ApiOutput<>("policyInfo", policyInfo);
    }

    /**
     * 策略 新增
     *
     * @param addPolicyVo
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiOutput add(@RequestBody AddPolicyVo addPolicyVo) {
        policyBusiness.add(addPolicyVo);
        return new ApiOutput<>();
    }

    /**
     * 策略集 更新
     */
    @RequestMapping(value = "/{policyId}/update", method = RequestMethod.POST)
    public ApiOutput update(@PathVariable(value = "policyId") Long policyId,
                            @RequestBody UpdatePolicyVo policyVo) {
        policyBusiness.update(policyId, policyVo);
        return new ApiOutput<>();
    }

    /**
     * 策略集删除
     *
     * @param policyId
     * @return
     */
    @RequestMapping(value = "/{policyId}/delete", method = RequestMethod.POST)
    public ApiOutput delete(@PathVariable(value = "policyId") Long policyId) {
        policyBusiness.delete(policyId);
        return new ApiOutput<>();
    }


    /**
     * 执行者  集合
     *
     * @param executorId
     * @return
     */
    @RequestMapping(value = "/{executorId}/list", method = RequestMethod.POST)
    public ApiOutput queryExecutorList(@PathVariable(value = "executorId") Long executorId) {

        List<ExecutorPolicyVo> executorPolicyVoList = policyBusiness.queryPolicyList(executorId);
        return new ApiOutput<>("list", executorPolicyVoList);
    }


    /**
     * 策略 集合排序
     *
     * @return
     */
    @RequestMapping(value = "/sort/update", method = RequestMethod.POST)
    public ApiOutput updatePolicySort(@RequestBody PolicySortVo policySortVo) {
        policyBusiness.updatePolicySort(policySortVo);
        return new ApiOutput<>();
    }


}
